#include<vector>
#include<iostream>
using std::vector;


class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        int i = 0;
        int j = matrix[0].size()-1;
        while (i < matrix.size() && j >= 0) {
            if (matrix[i][j] == target) return true;
            else if (matrix[i][j] > target) {
                j --;
            }
            else {
                i ++;
            }
        }
        return false;
    }

    bool search(vector<vector<int>>& mat, int target, int i1, int j1, int i2, int j2) {
        std::cout << "(" << i1 << "," << j1 << "," << i2 << "," << j2 << ")\n";
        if (!(i2 >= i1 && j2 >= j1 && i2 < mat.size() && j2 < mat[0].size() && i1 >= 0 && j1 >= 0)) return false;
        int midi = (i1 + i2) / 2;
        int midj = (j1 + j2) / 2;
        int v = mat[midi][midj];
        if (v == target) return true;
        else if (v > target && (search(mat, target, i1, j1, midi, midj-1) || search(mat, target, i1, midj, midi-1, midj)))
            return true;
        else if (v < target && (search(mat, target, midi, midj+1, i2, j2) || search(mat, target, midi+1, midj, i2, midj)))
            return true;
        else {
            return search(mat, target, i1, midj+1, midi-1, j2) || search(mat, target, midi+1, j1, i2, midj-1);
        }
        
    }
};

int main() {
    int m, n, target;
    int tmp;
    std::cin >> m >> n >> target;
    std::cout << "(" << m << ", " << n << ")\n";
    vector<vector<int>> input(m, vector<int>(n, 0));
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            std::cin >> tmp;
            input[i][j] = tmp;
            std::cout << input[i][j] << " ";

        }
        std::cout << "\n";
    }
    auto res = Solution().searchMatrix(input, target);
    std::cout << "find: " << res << "\n";
    return 0;
}